<?php
namespace Home\Controller;
use Think\Controller;
header("Content-type: text/html; charset=utf-8");
class CommonController extends Controller {
    public function index(){
        $this->show();
    }

    // 权限的初始化
    public function  _initialize(){
       $uid=$_SESSION['id'];
       $path=MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;//访问路径
       if(!M('auth_rule')->where(array('name'=>$path))->find()){
          return;
       }else{
           $auth=new \Think\Auth();
           $res= $auth->check($path,$uid);
           if (!$res){
            $this->error('你没此权限',U('admin/index/welcome'));
            }
       };
    }
    


    // 订单增加
    public function order_add($id,$mac_id,$pay_way){
           $res=M('shop_goods')->where(array('id'=>$id,'mac_id'=>$mac_id))->find();//取出对应商品数据
          $chop=M('machine')->where(array('id'=>$mac_id))->find();//取出对应数据
          if($chop['paper_cup']!=0 && $chop['material']!=0  &&  (($chop['row1']!=0) || ($chop['row2']!=0)  || ($chop['row3']!=0) || ($chop['row4']!=0) )) {
              $data['shop_good_name'] =$res['shop_good_name'];
              $data['shop_good_price']=$res['shop_good_price'];
              $data['create_time']=time();
              $data['mac_id']=$res['mac_id'];
              $data['pay_way']=$pay_way;//支付方式
              $data['out_trade_no']=date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);//生成订单号      
              if(M('sold_goods')->add($data)){//订单存入数据库
                  return $data['out_trade_no'];//返回订单号
              }
            
          }else{
              return 0;
          }
          
    }
}